package com.lanwf.admin.sys.oplog;

import com.jfinal.aop.Inject;
import com.jfinal.core.Path;
import com.jfinal.kit.Ret;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.lanwf.admin.BaseController;
import com.lanwf.IAdminIndexController;
import com.lanwf.admin.sys.PermissionService;
import com.lanwf.common.model.SysOplog;
import com.lanwf.admin.utils.Result;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: Lanwf
 * @Date: 2021/12/24 10:55
 * @Description:
 */
@Path(value = "/admin/oplog", viewPath = "/admin/sys/oplog")
public class OpLogAdminController extends BaseController implements IAdminIndexController {

    @Inject
    PermissionService permissionService;

    @Override
    public void index() {

        set("permission",permissionService.getPermission(getAccountId(),getInt(0)));
        render("index.html");
    }

    @Override
    public void paginate() {
        Integer p = getInt("pageNum", 1);
        Integer s = getInt("pageSize", 10);
        String orderByColumn = get("orderByColumn", "");
        String isAsc = get("isAsc", "");
        String title = get("title", "");
        List<Object> param = new ArrayList<>();
        String sql = "";
        sql = " from sys_oplog where 1=1 ";
        if (StrKit.notBlank(title)) {
            sql += " and username like ? or classname like ? or methodname like ? ";
            param.add("%" + title + "%");
            param.add("%" + title + "%");
            param.add("%" + title + "%");
        }
        sql += " order by ";
        if (StrKit.notBlank(orderByColumn)) {
            sql += "" + orderByColumn + " " + isAsc;
        }
        Page<SysOplog> paginate = SysOplog.dao.paginate(p, s, "select *", sql, param.toArray());
        renderJson(new Result<>(paginate.getTotalRow(), paginate.getList()));
    }

    @Override
    public void add() {
    }

    @Override
    public void save() {
    }

    @Override
    public void edit() {
    }

    @Override
    public void update() {
    }

    @Override
    public void delete() {
        SysOplog.dao.deleteById(getInt(0));
        renderJson(Ret.ok().set("msg", "删除成功"));
    }

}

